<?php

/**
 * This is the model class for table "form_thong_tin_khac".
 *
 * The followings are the available columns in table 'form_thong_tin_khac':
 * @property string $id
 * @property string $ten_don_vi
 * @property string $thong_tin_dang_tai
 * @property string $noi_dung
 * @property string $ngay_xuat_ban
 * @property string $so_bao_dang
 * @property string $tinh_trang_thong_tin
 * @property string $ma_thong_tin
 * @property string $thong_tin_chuyen_tien
 * @property string $id_nguoi_tao
 * @property string $id_nguoi_chinh_sua
 * @property string $ngay_tao
 * @property string $ngay_chinh_sua
 * @property integer $status
 * @property string $id_nguoi_duyet
 * @property string $da_thanh_toan
 * @property string $tong_tien
 * @property string $ngay_duyet
 * @property string $image_url
 * @property string $ly_do
 *
 * The followings are the available model relations:
 * @property ThanhVien $idNguoiDuyet
 * @property ThanhVien $idNguoiTao
 */
class FormThongTinKhac extends CActiveRecord
{
	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'form_thong_tin_khac';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('status', 'numerical', 'integerOnly'=>true),
			array('ten_don_vi, thong_tin_dang_tai, tinh_trang_thong_tin', 'length', 'max'=>250),
			array('so_bao_dang, ma_thong_tin, thong_tin_chuyen_tien', 'length', 'max'=>50),
			array('id_nguoi_tao, id_nguoi_chinh_sua, id_nguoi_duyet', 'length', 'max'=>20),
			array('da_thanh_toan, tong_tien', 'length', 'max'=>10),
			array('noi_dung, ngay_xuat_ban, ngay_tao, ngay_chinh_sua, ngay_duyet', 'safe'),
			// The following rule is used by search().
			// @todo Please remove those attributes that should not be searched.
			array('id, ten_don_vi, thong_tin_dang_tai, noi_dung, ngay_xuat_ban, so_bao_dang, tinh_trang_thong_tin, ma_thong_tin, thong_tin_chuyen_tien, id_nguoi_tao, id_nguoi_chinh_sua, ngay_tao, ngay_chinh_sua, status, id_nguoi_duyet, da_thanh_toan, tong_tien, ngay_duyet', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'idNguoiDuyet' => array(self::BELONGS_TO, 'ThanhVien', 'id_nguoi_duyet'),
			'idNguoiTao' => array(self::BELONGS_TO, 'ThanhVien', 'id_nguoi_tao'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'ten_don_vi' => 'Tên đơn vị',
			'thong_tin_dang_tai' => 'Thông tin đăng tải',
			'noi_dung' => 'Nội dung',
			'ngay_xuat_ban' => 'Ngày xuất bản',
			'so_bao_dang' => 'Số báo đăng',
			'tinh_trang_thong_tin' => 'Tình trạng thông tin',
			'ma_thong_tin' => 'Mã thông tin',
			'thong_tin_chuyen_tien' => 'Thông tin chuyển tiền',
			'id_nguoi_tao' => 'Người tạo',
			'id_nguoi_chinh_sua' => 'Người chỉnh sửa',
			'ngay_tao' => 'Ngày tạo',
			'ngay_chinh_sua' => 'Ngày chỉnh sửa',
			'status' => 'Status',
			'id_nguoi_duyet' => 'Người duyệt',
			'da_thanh_toan' => 'Đã thanh toán',
			'tong_tien' => 'Tong Tien',
			'ngay_duyet' => 'Ngay Duyet',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 *
	 * Typical usecase:
	 * - Initialize the model fields with values from filter form.
	 * - Execute this method to get CActiveDataProvider instance which will filter
	 * models according to data in model fields.
	 * - Pass data provider to CGridView, CListView or any similar widget.
	 *
	 * @return CActiveDataProvider the data provider that can return the models
	 * based on the search/filter conditions.
	 */
	public function search()
	{
		// @todo Please modify the following code to remove attributes that should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id,true);
		$criteria->compare('ten_don_vi',$this->ten_don_vi,true);
		$criteria->compare('thong_tin_dang_tai',$this->thong_tin_dang_tai,true);
		$criteria->compare('noi_dung',$this->noi_dung,true);
		$criteria->compare('ngay_xuat_ban',$this->ngay_xuat_ban,true);
		$criteria->compare('so_bao_dang',$this->so_bao_dang,true);
		$criteria->compare('tinh_trang_thong_tin',$this->tinh_trang_thong_tin,true);
		$criteria->compare('ma_thong_tin',$this->ma_thong_tin,true);
		$criteria->compare('thong_tin_chuyen_tien',$this->thong_tin_chuyen_tien,true);
		$criteria->compare('id_nguoi_tao',$this->id_nguoi_tao,true);
		$criteria->compare('id_nguoi_chinh_sua',$this->id_nguoi_chinh_sua,true);
		$criteria->compare('ngay_tao',$this->ngay_tao,true);
		$criteria->compare('ngay_chinh_sua',$this->ngay_chinh_sua,true);
		$criteria->compare('status',$this->status);
		$criteria->compare('id_nguoi_duyet',$this->id_nguoi_duyet,true);
		$criteria->compare('da_thanh_toan',$this->da_thanh_toan,true);
		$criteria->compare('tong_tien',$this->tong_tien,true);
		$criteria->compare('ngay_duyet',$this->ngay_duyet,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}

	/**
	 * Returns the static model of the specified AR class.
	 * Please note that you should have this exact method in all your CActiveRecord descendants!
	 * @param string $className active record class name.
	 * @return FormThongTinKhac the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

    protected function beforeSave()
    {
        $this->ngay_xuat_ban = Helper::getDateTime($this->ngay_xuat_ban);
        return parent::beforeSave(); // TODO: Change the autogenerated stub
    }

}
